<%@page import="net.sf.json.JSONObject"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/classes/DBHelper.class.jsp"%>
<%@ include file="/classes/CommonHelper.class.jsp"%>
<%!
public static boolean deleteFile(String fileName) {
    File file = new File(fileName);
    // 如果文件路径所对应的文件存在，并且是一个文件，则直接删除
    if (file.exists() && file.isFile()) {
        if (file.delete()) {
            System.out.println("删除单个文件" + fileName + "成功！");
            return true;
        } else {
            System.out.println("删除单个文件" + fileName + "失败！");
            return false;
        }
    } else {
        System.out.println("删除单个文件失败：" + fileName + "不存在！");
        return false;
    }
}
%>
<%
	//获取数据
	String zyfw_id = getParameter(request, "zyfw_id");
	JSONObject result = new JSONObject();
	if (nullOrEmpty(zyfw_id)) {
		result.put("status", -1);
		result.put("msg", "参数错误");
		out.println(result);
		return;
	}
	//先获取对象
	Map<String, Object> map = getObject("SELECT * FROM APP_ZYFW t WHERE t.zyfw_id = ?",
			new Object[] { zyfw_id });
	if (null == map) {
		result.put("status", -1);
		result.put("msg", "删除失败,对象不存在");
		out.println(result);
		return;
	}

	String file1 = (String) map.get("file1");
	if (null != file1) {
		deleteFile(file1);
	}
	String file2 = (String) map.get("file2");
	if (null != file2) {
		deleteFile(file2);
	}
	String sql = "DELETE FROM APP_ZYFW WHERE zyfw_id = ?";
	int i = executeUpdate(sql, new Object[] { zyfw_id });
	if (i >= 1) {
		result.put("status", 200);
		result.put("msg", "删除成功");
		out.println(result);
	} else {
		result.put("status", -1);
		result.put("msg", "删除失败");
		out.println(result);
	}
%>